package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.ShowVideoOrAudioDataBean;
import com.fancy.learncenter.common.Constant;
import com.fancy.learncenter.ui.activity.PlayVedioActivity;
import com.fancy.learncenter.ui.activity.base.MallCommonH5Activity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;
import com.fancy.learncenter.utils.Utils;

import java.util.List;

/**
 * Created by Hyy on 2016/12/28.
 */

public class FragmentShowVideoAdapter extends CommonRecycleViewAdapter<ShowVideoOrAudioDataBean.RecommendListBean> {
    private final int LEFT = 1;
    private final int RIGHT = 2;


    private Context mContext;

    public FragmentShowVideoAdapter(Context mContext, List<ShowVideoOrAudioDataBean.RecommendListBean> itemDatas) {
        super(mContext, R.layout.fragment_show_video_item, itemDatas);
        this.mContext = mContext;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final ShowVideoOrAudioDataBean.RecommendListBean item, int position) {
        SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);
        simpleDraweeView.setImageURI(Utils.getPicPath(item.getWholeShowResourceCoverImg(), 200, 200));

        TextView title = customViewHold.getView(R.id.title);
        title.setText(item.getShowResourceName());

        TextView time = customViewHold.getView(R.id.time);
        time.setText(item.getResourceDurationStr());

        TextView pv_num = customViewHold.getView(R.id.pv_num);
        pv_num.setText(item.getPagevies() + "次浏览");

        TextView praise_num = customViewHold.getView(R.id.praise_num);
        praise_num.setText(item.getPraise() + "人点赞");


        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                 entityType	Integer	业务类型	1 视频 2 音频 3 商品 4 活动 5 资讯
//                 frontType	Integer	前端类型	1 原生 2 H5
                if (item.getEntityType().equals("1")) {
                    if (item.getFrontType().equals("1")) {
                        Intent intent = new Intent(mContext, PlayVedioActivity.class);
                        intent.putExtra(Constant.showResourceCoverImg, item.getWholeShowResourceCoverImg());
                        intent.putExtra(Constant.playLink, item.getWholePlayLink());
                        intent.putExtra(Constant.showResourceId, item.getShowResourceId());
                        intent.putExtra(Constant.showResourceName, item.getShowResourceName());
                        intent.putExtra(Constant.intro, item.getShowResourceName());
                        mContext.startActivity(intent);
                    } else if (item.getFrontType().equals("2")) {
                        Intent intent = new Intent(mContext, MallCommonH5Activity.class);
                        intent.putExtra(MallCommonH5Activity.URL_KEY, item.getPlayLink());
                        mContext.startActivity(intent);
                    }
                }


            }
        });
    }

    @Override
    public int getAdapterItemViewType(int position) {
        if (position % 2 == 0) {
            return LEFT;
        } else {
            return RIGHT;
        }
    }

    @Override
    public CustomViewHold onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        if (viewType == LEFT) {
            return CustomViewHold.creatViewHolder(mContext, parent, R.layout.fragment_show_video_item);
        } else {
            return CustomViewHold.creatViewHolder(mContext, parent, R.layout.fragment_show_video_item2);
        }
    }

}
